var iFDU = require('../../utils/iFDU.js');
var app = getApp()
Page({
  data: {
    config: app.config,
    goodsId: 0,
    sleeveWord: '',
    sleeveWordType: 1
  },

  onLoad: function (options) {
    var sleeveWord = options.sleeveWord ? options.sleeveWord : '';
    this.setData({
      goodsId: options.goodsId,
      sleeveWord: options.sleeveWord,
      sleeveWordType: options.sleeveWordType,
    });
  },

  sleeveWordInput: function (e) {
    this.setData({
      sleeveWord: e.detail.value
    })
  },

  selectSleeveType: function (e) {
    this.setData({
      sleeveWordType: e.currentTarget.dataset.type
    })
  },

  saveSleeveWord: function (e) {
    var that = this;
    if (!that.data.sleeveWord) {
      iFDU.toast.showToast({
        title: '请输入绣字内容',
        mask: false
      })
      return;
    }
    if (!/^[a-zA-Z0-9\.]{1,15}$/.test(that.data.sleeveWord)) {
      iFDU.toast.showToast({
        title: '仅支持15字符以下的英文/数字/点号内容',
        mask: false
      })
      return;
    }

    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];
    var goodsList = prevPage.data.goodsList;
    for (var index in goodsList) {
      var item = goodsList[index];
      if (item.goods_id == that.data.goodsId) {
        item['sleeve_word'] = that.data.sleeveWord
        item['sleeve_word_type'] = that.data.sleeveWordType
        break;
      }
    }
    prevPage.setData({
      goodsList: goodsList
    })
    wx.navigateBack({
      
    })
  },

  onShareAppMessage: function (res) {
    var that = this;
    return {
      title: '你的衬衫，应该是定制的！',
      imageUrl: 'http://s.i-fdu.com/runto/wxa/s/yjshare.jpeg',
      path: 'pages/home/home',
      success: function (res) {
      },
      fail: function (res) {
      }
    }
  }
})